package com.music.dao;

import com.laoxuai.beans.annotation.Component;
import com.laoxuai.ibatis.support.BaseDao;
import com.music.pojo.User;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

@Component
public class UserDao extends BaseDao<User, Integer> {
    /**
     * 根据用户名获取用户信息
     * @param name
     * @return
     * @throws SQLException
     */
    public User getUserByName(String name) throws SQLException {
        String sql = "select * from t_user where name=? limit 1";
        return runner.query(sql,new BeanHandler<>(User.class, processor), name);
    }

    /**
     * 根据用户名查询除自己以外的用户信息
     * @param name
     * @return
     */
    public User getOtherUserByName(String name,Integer userId) throws SQLException {
        String sql="select *from t_user where name=? and user_id!=?";
        return runner.query(sql,new BeanHandler<>(User.class),name,userId);
    }
}
